package com.hanyxx.thread;
import lombok.SneakyThrows;

/**
 * @author layman
 * @date 2021/2/5
 */
public class ThreadDaemon04 {
    public static void main(String[] args) throws InterruptedException {
        demo04 demo04 = new demo04();
        //当把demo04设置为守护线程时，主线程结束时，demo04就会结束。
        demo04.setDaemon(true);
        demo04.start();
        Thread.sleep(2000);
        System.out.println("main线程结束");
    }
}
class demo04 extends  Thread{
    @SneakyThrows
    @Override
    public void run() {
        while(true){
            System.out.println("time= "+System.currentTimeMillis());
            Thread.sleep(500);
        }
    }
}


